package org.hxyjs.dao.impl;

import org.hxyjs.dao.ActivitytypeDao;
import org.hxyjs.entity.Activitytype;
import org.hxyjs.mapper.ActivitytypeMapper;
import org.hxyjs.page.PageInfo;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Repository("activitytypeDao")//一般实现类不会直接生成默认对象名 而是使用 接口的默认对象名
public class ActivitytypeDaoImpl implements ActivitytypeDao {
    @Resource //autowired 会装配能够直接扫描到的对象  resource spring容器运行的时候才找到需要的对象  注入
    private ActivitytypeMapper activitytypeMapper;

    public List<Activitytype> getAllActivitytypes() throws Exception {
        return activitytypeMapper.selectByExample(null);
    }

    @Override
    public Activitytype getActivitytypeByAtno(String ano) throws Exception {
        return activitytypeMapper.selectByPrimaryKey(ano);
    }


    @Override
    public Integer deleteActivitytypeByAtno(String ano) {
        return activitytypeMapper.deleteByPrimaryKey(ano);
    }

    @Override
    public Integer updateActivitytype(Activitytype activitytype) {
        return activitytypeMapper.updateByPrimaryKey(activitytype);
    }

    @Override
    public Integer addActivitytypeByAno(Activitytype activitytype ) {
        activitytype.setAtno(initId());
        return activitytypeMapper.insertSelective(activitytype);
    }

    @Override
    public List<Activitytype> getActivitytypeByPage(PageInfo pageInfo) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("currPage", pageInfo.getCurrPage());
        map.put("pageSize", pageInfo.getPageSize());
        int itemCount = (int) activitytypeMapper.countByExample(null);
        pageInfo.setItemCount(itemCount);
        return activitytypeMapper.getAdminByPage(map);
    }

    public String initId() {
        String maxAtno = activitytypeMapper.getMaxAtno();
        return org.hxyjs.utils.GenNumTools.initId("3", 3, maxAtno);
    }


}